{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Using the Pandas Data Frame as a Database..ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Tanu-N-Prabhu/Python/blob/master/Using_the_Pandas_Data_Frame_as_a_Database_.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-9gSDGnYguxU",
        "colab_type": "text"
      },
      "source": [
        "# Using the Pandas Data Frame as a Database."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_N52RtPrgzbs",
        "colab_type": "text"
      },
      "source": [
        "## Let us understand how to use the pandas data frame as a database."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SCroLvrXg2Om",
        "colab_type": "text"
      },
      "source": [
        "![alt text](https://miro.medium.com/max/2400/1*9v51-jsfHtk6fgAIYLoiHQ.jpeg)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uAPlY_zbg4zj",
        "colab_type": "text"
      },
      "source": [
        "Before starting let me quickly tell about the pandas data frame: It is a python library that provides high performance, and easy-to-use data structure for data analysis tools for python programming language. Below is an article that explains the primitive manipulations performed on the pandas data frame.\n",
        "\n",
        "[Pandas Data Frame](https://towardsdatascience.com/manipulating-the-data-with-pandas-using-python-be6c5dfabd47?source=post_page-----282edec5a3ab----------------------)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8uPqN7KlhLOJ",
        "colab_type": "text"
      },
      "source": [
        "Let’s get started, this is a programming tutorial so I recommend you guys to practice side by side with me. I favor using Google Colab or Jupyter notebooks. To brief out, I will teach you guys how to use the pandas data frame as a database to store data and perform some rudimentary operations on it. This data frame has almost all the features compared to a database. It almost resembles a database."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7s483yvBhNgx",
        "colab_type": "text"
      },
      "source": [
        "**Steps that will be followed in this tutorial are**\n",
        "1. Creating a pandas data frame\n",
        "2. Adding a row to the data frame\n",
        "3. Deleting a row from the data frame\n",
        "4. Accessing the value of a row from the data frame\n",
        "5. Changing the value of a row in the data frame\n",
        "\n",
        "**Let see how can we perform all the steps declared above**"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vQlzrvjZhUq2",
        "colab_type": "text"
      },
      "source": [
        "## 1. Creating a pandas data frame\n",
        "\n",
        "To create the data frame, first you need to import it, and then you have to specify the column name and the values in the order shown below:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "9O8VgzD2XabL",
        "colab": {}
      },
      "source": [
        "import pandas as pd"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "P7hkZegChaGo",
        "colab_type": "text"
      },
      "source": [
        "Let’s create a new data frame. I am storing the company name, Founders, Founded and Number of Employees. You can store the data of your choice inside the data frame."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "8cb0319d-e856-469b-b963-43d49070d736",
        "id": "j-nP-TTjXaLr",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 202
        }
      },
      "source": [
        "df = pd.DataFrame({'Company Name':['Google', 'Microsoft', 'SpaceX', 'Amazon', 'Samsung'], \n",
        "                   'Founders':['Larry Page, Sergey Brin', 'Bill Gates, Paul Allen','Elon Musk','Jeff Bezos', 'Lee Byung-chul'], \n",
        "                   'Founded': [1998, 1975, 2002, 1994, 1938], \n",
        "                   'Number of Employees': ['103,459', '144,106', '6,500', '647,500', '320,671']})\n",
        "df"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Amazon</td>\n",
              "      <td>Jeff Bezos</td>\n",
              "      <td>1994</td>\n",
              "      <td>647,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name                 Founders  Founded Number of Employees\n",
              "0       Google  Larry Page, Sergey Brin     1998             103,459\n",
              "1    Microsoft   Bill Gates, Paul Allen     1975             144,106\n",
              "2       SpaceX                Elon Musk     2002               6,500\n",
              "3       Amazon               Jeff Bezos     1994             647,500\n",
              "4      Samsung           Lee Byung-chul     1938             320,671"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AU7BgWcthdAw",
        "colab_type": "text"
      },
      "source": [
        "Don’t worry there is nothing complicated here, it’s just the values that might confuse you as they are just Company name, founders, founded, etc. Be careful with the brackets it can make your life miserable if you mess with it.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "9FEJJA8lXZ7G"
      },
      "source": [
        "## 2. Adding a new row to the data frame\n",
        "\n",
        "Think now you want to add a new row to the data frame, all you can do is add the new row to the end of the data frame or any specific location of your choice.\n",
        "\n",
        "**Case 1: Adding a row at the end of the data frame:**\n",
        "\n",
        "To append the row at the end of the data frame, you need to use the “**append method**” by passing the values you want to append. Below is the official documentation of append function:\n",
        "\n",
        "[Append Method](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.append.html?source=post_page-----282edec5a3ab----------------------)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "52I1sxf4htgz",
        "colab_type": "text"
      },
      "source": [
        "Let's create a new data frame with new values and then append that to the end of the existing data frame."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "b41fee36-4328-4d93-87ff-b79ed8f6733b",
        "id": "WhUFtf8JXZrx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 79
        }
      },
      "source": [
        "df1 = pd.DataFrame({'Company Name':['WhatsApp'], 'Founders':['Jan Koum, Brian Acton'], 'Founded': [2009], 'Number of Employees': ['50'] })\n",
        "df1"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>WhatsApp</td>\n",
              "      <td>Jan Koum, Brian Acton</td>\n",
              "      <td>2009</td>\n",
              "      <td>50</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name               Founders  Founded Number of Employees\n",
              "0     WhatsApp  Jan Koum, Brian Acton     2009                  50"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kXdSbWZjhweB",
        "colab_type": "text"
      },
      "source": [
        "df1 is a new data frame that we want to append to the existing data frame df"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "40b5c181-1476-4b7e-a35b-e84139f82ed0",
        "id": "1tiDHl1iXZa6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 233
        }
      },
      "source": [
        "df = df.append(df1, ignore_index=True)\n",
        "df"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Amazon</td>\n",
              "      <td>Jeff Bezos</td>\n",
              "      <td>1994</td>\n",
              "      <td>647,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>WhatsApp</td>\n",
              "      <td>Jan Koum, Brian Acton</td>\n",
              "      <td>2009</td>\n",
              "      <td>50</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name                 Founders  Founded Number of Employees\n",
              "0       Google  Larry Page, Sergey Brin     1998             103,459\n",
              "1    Microsoft   Bill Gates, Paul Allen     1975             144,106\n",
              "2       SpaceX                Elon Musk     2002               6,500\n",
              "3       Amazon               Jeff Bezos     1994             647,500\n",
              "4      Samsung           Lee Byung-chul     1938             320,671\n",
              "5     WhatsApp    Jan Koum, Brian Acton     2009                  50"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qQfEX3qIhyg4",
        "colab_type": "text"
      },
      "source": [
        "**Case 2: Adding a new row at a specific location**\n",
        "\n",
        "Let us now add a new row of values at index 3, meaning below “SpaceX” company. To do this, we can use the pandas “iloc method” by specifying the index and the values to be added. Below is the documentation of iloc method\n",
        "\n",
        "[iloc method](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html?source=post_page-----282edec5a3ab----------------------)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "ba67258d-5531-48f5-be43-748e587c16fe",
        "id": "M6bzDwYbXZCh",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 233
        }
      },
      "source": [
        "df.iloc[3] = ['YouTube', 'Chad Hurley, Steve Chen, Jawed Karim', 2005, '2,800']\n",
        "df"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>YouTube</td>\n",
              "      <td>Chad Hurley, Steve Chen, Jawed Karim</td>\n",
              "      <td>2005</td>\n",
              "      <td>2,800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>WhatsApp</td>\n",
              "      <td>Jan Koum, Brian Acton</td>\n",
              "      <td>2009</td>\n",
              "      <td>50</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name  ... Number of Employees\n",
              "0       Google  ...             103,459\n",
              "1    Microsoft  ...             144,106\n",
              "2       SpaceX  ...               6,500\n",
              "3      YouTube  ...               2,800\n",
              "4      Samsung  ...             320,671\n",
              "5     WhatsApp  ...                  50\n",
              "\n",
              "[6 rows x 4 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OhnW6WiJh7Kc",
        "colab_type": "text"
      },
      "source": [
        "With the help of iloc we can add a new row anywhere within the data frame.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "JsHZvRpiXYxG"
      },
      "source": [
        "## 3. Deleting a row from the data frame\n",
        "\n",
        "Some times there might be few cases where you actually need to remove unnecessary data from the database or data frame. To do so, the “**drop method**” in pandas gets the job done. Let’s see two cases such as deleting a row with its index and deleting a row with the help of a value. Below is the documentation of pandas drop method:\n",
        "\n",
        "[Pandas drop method](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html?source=post_page-----282edec5a3ab----------------------)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Nu8WJnlFiTGq",
        "colab_type": "text"
      },
      "source": [
        "**Case 1: Deleting a row with its index**\n",
        "\n",
        "Now this can be done by mentioning the index inside the drop method"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "7ddfc267-106a-478b-bf79-745164aeffe6",
        "id": "8IEi3ghgXYgU",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 202
        }
      },
      "source": [
        "df = df.drop([df.index[5]])\n",
        "df"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>YouTube</td>\n",
              "      <td>Chad Hurley, Steve Chen, Jawed Karim</td>\n",
              "      <td>2005</td>\n",
              "      <td>2,800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name  ... Number of Employees\n",
              "0       Google  ...             103,459\n",
              "1    Microsoft  ...             144,106\n",
              "2       SpaceX  ...               6,500\n",
              "3      YouTube  ...               2,800\n",
              "4      Samsung  ...             320,671\n",
              "\n",
              "[5 rows x 4 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pXyIOyjiiV-Q",
        "colab_type": "text"
      },
      "source": [
        "As seen above the index 5 i.e **WhatsApp** company’s row was removed completely."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "plwPUV4liWqJ",
        "colab_type": "text"
      },
      "source": [
        "**Case 2: Deleting a row with the help of a value.**\n",
        "\n",
        "Now let us see how can we delete a row with its value."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "c416f17e-3c5b-4e11-9ea1-da3909185657",
        "id": "2_A9aNPWXYKJ",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 171
        }
      },
      "source": [
        "df = df[df.Founders != 'Chad Hurley, Steve Chen, Jawed Karim']\n",
        "df"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name                 Founders  Founded Number of Employees\n",
              "0       Google  Larry Page, Sergey Brin     1998             103,459\n",
              "1    Microsoft   Bill Gates, Paul Allen     1975             144,106\n",
              "2       SpaceX                Elon Musk     2002               6,500\n",
              "4      Samsung           Lee Byung-chul     1938             320,671"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "N_MTuvAfibEg",
        "colab_type": "text"
      },
      "source": [
        "Now the **YouTube** company’s row is deleted with the help of providing its values."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tWDmQX1vjaYY",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "iyoNT_GEXX2f"
      },
      "source": [
        "## 4. Accessing the value of a row from the data frame\n",
        "Accessing the value from the data frame is pretty trivial, all you have to do is use “loc method”. The loc method accepts the index as the parameter, by specifying it you can retrieve the value from it. Below is the documentation of loc method:\n",
        "\n",
        "[loc method](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html?source=post_page-----282edec5a3ab----------------------)\n",
        "\n",
        "Now, let us think that we need to access the 3nd-row values, to do call **loc[2]** and your job is done. The rows are stored from the 0th index hence 3rd-row index is 2 (0, 1, 2)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "9f7929f7-ea64-4e24-c290-e799a05297a4",
        "id": "fTEEb8rpXXjb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 104
        }
      },
      "source": [
        "df.loc[2]"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Company Name              SpaceX\n",
              "Founders               Elon Musk\n",
              "Founded                     2002\n",
              "Number of Employees        6,500\n",
              "Name: 2, dtype: object"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FkLsRbyzirbB",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "b128IOKfXXPh"
      },
      "source": [
        "## 5. Changing the value of a row in the data frame\n",
        "This can be done by using the “at” method. To use the “at” method all you have to do is specify its index and the location of the column name and then the value that you need to change. Below is the documentation of the “**at**” method:\n",
        "\n",
        "[At method](https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.at.html?source=post_page-----282edec5a3ab----------------------)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T-hm6zM7i2ct",
        "colab_type": "text"
      },
      "source": [
        "For example, let's think that I want to change the number of employees of Microsoft to 200,000 (I am sorry Microsoft I have to do this for my tutorial)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "gh803dQMXWip",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 171
        },
        "outputId": "102a79e5-207d-4db1-ac05-29de01cdb55c"
      },
      "source": [
        "df.at[1, 'Number of Employees'] = '200,000'\n",
        "df # This is after the change of value (Microsoft)"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>200,000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name                 Founders  Founded Number of Employees\n",
              "0       Google  Larry Page, Sergey Brin     1998             103,459\n",
              "1    Microsoft   Bill Gates, Paul Allen     1975             200,000\n",
              "2       SpaceX                Elon Musk     2002               6,500\n",
              "4      Samsung           Lee Byung-chul     1938             320,671"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "outputId": "75a353e7-978f-47f8-d176-32f11e5a9a95",
        "id": "PqkjleAmXWFB",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 171
        }
      },
      "source": [
        "df  # This is before the change of value (Microsoft)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Company Name</th>\n",
              "      <th>Founders</th>\n",
              "      <th>Founded</th>\n",
              "      <th>Number of Employees</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Google</td>\n",
              "      <td>Larry Page, Sergey Brin</td>\n",
              "      <td>1998</td>\n",
              "      <td>103,459</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Microsoft</td>\n",
              "      <td>Bill Gates, Paul Allen</td>\n",
              "      <td>1975</td>\n",
              "      <td>144,106</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>SpaceX</td>\n",
              "      <td>Elon Musk</td>\n",
              "      <td>2002</td>\n",
              "      <td>6,500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Samsung</td>\n",
              "      <td>Lee Byung-chul</td>\n",
              "      <td>1938</td>\n",
              "      <td>320,671</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  Company Name                 Founders  Founded Number of Employees\n",
              "0       Google  Larry Page, Sergey Brin     1998             103,459\n",
              "1    Microsoft   Bill Gates, Paul Allen     1975             144,106\n",
              "2       SpaceX                Elon Musk     2002               6,500\n",
              "4      Samsung           Lee Byung-chul     1938             320,671"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1WAzrl32i6ZB",
        "colab_type": "text"
      },
      "source": [
        "There you go this is how you can use the pandas data frame as a database. You have successfully completed all the steps of the tutorial. I hope you have enjoyed reading it. There are plenty of more operations, functions or methods that can be performed on a data frame. I cannot explain every operation in one stretch, let me know if you guys need more tutorials about these concepts. Don’t forget to read all the documentation link of the official pandas data frame that I have provided in this tutorial. Until then see you. Have a good day.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CYl4LRNljYh6",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    }
  ]
}